﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SalesLeads.aspx.cs" Inherits="Skyworth.CRM.Web.CustomerManagement.SalesLeads" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>线索管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <%--[if IE]>
     <link href="../themes/css/ieHack.css" rel="stylesheet" type="text/css" />
    <![endif]--%>
    <link href="../themes/default/style.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/core.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/pages.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/wbox.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/Messagebox.css" rel="stylesheet" type="text/css" />
    <link href="../javascripts/My97DatePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="../themes/css/jquery.cluetip.css" type="text/css" />
    <script src="../javascripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../javascripts/dwz.core.js" type="text/javascript"></script>
    <script src="../javascripts/MessageBox.js" type="text/javascript"></script>
    <script src="../javascripts/jquery.tablesorter.min.js" type="text/javascript"></script>
    <script src="../javascripts/wbox.js" type="text/javascript"></script>
    <script src="../javascripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../javascripts/jquery.cluetip.min.js" type="text/javascript"></script>
    <script src="../javascripts/dwz.pagination.js" type="text/javascript"></script>
    <script src="../javascripts/json2.js" type="text/javascript"></script>
    <script type="text/javascript" >
        var addWindow;
        //下一页
        function dwzPageBreak(args) {
            $("#pageNum").val(args["pageNum"]);
            $(" #selectedId").val("");
            GetDatas();
        }

        //设置翻页
        function SetPager(pagerId, pageMsgId, numPerPage, currentPage, totalRecords, totalPages) {
            $(pageMsgId).text("  共【" + totalRecords + "】条，【" + totalPages + "】页");
            $(pagerId).each(function () {
                var $this = $(this);
                //alert($this.attr("targetType").toString());
                $this.pagination({
                    targetType: $this.attr("targetType"),
                    totalCount: totalRecords,
                    numPerPage: numPerPage,
                    pageNumShown: $(this).attr("pageNumShown"),
                    currentPage: currentPage
                });
            });
        }

        function DeleteData(id) {
            var paramList = '{"id":"' + id + '"}';
            $.ajax({
                type: "POST",
                url: "SalesLeads.aspx/Delete",
                contentType: "application/json; charset=utf-8",
                data: paramList,
                dataType: "json",
                success: function (data) {
                    if (data.d) {
                        GetDatas();
                    }
                },
                error: function (msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，删除失败！", Icon: IconType.Warning }); }
            })
        }

        function GetDatas() {            
            var paramList = new Object();
            paramList.ledCode = $("#txtCode").val();
            paramList.ledName = $("#txtName").val();
            paramList.ledDate = $("#txtDate").val();
            paramList.orderField = $("#orderField").val();
            paramList.orderValue = $("#orderValue").val();
            paramList.pageIndex = $("#pageNum").val();
            paramList.pagePerSize = $("#numPerPageSelect").val();
            //debugger;
            $.ajax({
                type: "POST",
                url: "SalesLeads.aspx/GetDatas",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(paramList),
                dataType: "json",
                success: function (data) {
                    var dataTable = jQuery.parseJSON(data.d);                    
                    //填充数据
                    $("#ActiveList tbody").empty();
                    var lists = "";
                    $.each(dataTable.rows, function (i, item) {
                        var fdate = eval("new " + item.FDate.replace(/\//g, ""));
                        lists = lists + "<tr rel='" + item.FItemId + "'>" + "<td><a href='javascript:void(0)' rel='SalesLeadsDetail.aspx?LeadId="
                        + item.FItemId + "'>" + item.FNumber + "</a></td><td>" + item.FComName + "</td><td>" + item.FAddress + "</td>"
                        + "<td>" + item.FProducts + "</td><td>" + item.FWebsite + "</td><td>" + item.EmpName + "</td>"
                        + "<td>" + item.FArea + "</td><td>" + item.FChannel + "</td><td>" + fdate.getFullYear() + "-" + (fdate.getMonth() + 1) + "-" + fdate.getDate() + "</td>"
                        + "<td>" + item.FMakerName + "</td>"
                        + "<td><a href='javascript:void(0)' class='openWindow' id='" + item.FItemId + "'><span>设置活动</span></a>&nbsp;&nbsp;"
                        + "<a href='javascript:void(0)' class='openWindow2' id='" + item.FItemId + "'><span>设置商业报价</span></a></td>"
                        + "</tr>";
                    })
                    $(lists).appendTo($("#ActiveList tbody"));

                    //绑定事件
                    $("#ActiveList tr:nth-child(even)").attr('class', "trbg");
                    $("#ActiveList tbody tr").click(function () {
                        $(" #selectedId").val($(this).attr("rel"));
                        $(this).addClass("selected");
                        $(this).siblings("tr").removeClass("selected");
                    }).hover(function () {
                        $(this).addClass('hover');
                    }, function () {
                        $(this).removeClass('hover');
                    })                    
                    $(".tableList table.list tbody tr a.openWindow").click(function () {
                        var code = $(this).parent("td").parent("tr").children("td").eq(0).text();
                        //alert(code);
                        addWindow = $(this).wBox({ title: "修改活动信息", requestType: "iframe", target: "EditSalesActive.aspx?Type=add&LeadId=" + $(this).parent().parent().attr("rel") + "&LeadCode=" + code, iframeWH: { width: 600, height: 480} });
                        addWindow.showBox();
                        //return false; //阻止事件冒泡
                    })
                    $(".tableList table.list tbody tr a.openWindow2").click(function () {
                        var code = $(this).parent("td").parent("tr").children("td").eq(0).text();
                        //alert(code);
                        addWindow = $(this).wBox({ title: "修改报价信息", requestType: "iframe", target: "EditCustQuoteQuery.aspx?Type=add&LeadId=" + $(this).parent().parent().attr("rel") + "&LeadCode=" + code, iframeWH: { width: 600, height: 400} });
                        addWindow.showBox();
                        //return false; //阻止事件冒泡
                    });
                    $("div.buttonActive").hover(function () { $(this).addClass("buttonActiveHover"); },
                                function () { $(this).removeClass("buttonActiveHover"); })

                    $("ul.toolBar li").hover(function () { $(this).addClass("hover"); },
                                              function () { $(this).removeClass("hover"); })
                    //绑定表格行事件                        
                    $(".tableList table.list").tablesorter();

                    $(".tableList table.list tbody tr:nth-child(even)").attr('class', "trbg");
                    $(".tableList table.list tbody tr").hover(function () { $(this).addClass("hover"); },
                                            function () { $(this).removeClass("hover"); }).click(function () {
                                                $(this).addClass("selected")
                                                $(this).siblings().removeClass("selected");
                                                $("#selectedLeadsID").val($(this).attr("rel"));
                                            }).dblclick(function () {
                                                addWindow = $("#selectedLeadsID").wBox({ title: "修改线索信息", requestType: "iframe", target: "EditSalesLeads.aspx?Type=update&LeadId=" + $(this).attr("rel"), iframeWH: { width: 600, height: 350} });
                                                addWindow.showBox();
                                            });
                    SetPager("#pageId", "#pageMsg", $("#numPerPageSelect").val(), $("#pageNum").val(), dataTable.totalRecords, dataTable.totalPages);                    
                    $("#ActiveList tbody tr").each(function () {
                        $(this).find("td").eq(0).find("a").cluetip({ cluetipClass: 'jtip', width: '760px', sticky: true, activation: 'click', closePosition: 'title', arrows: true, closeText: '<img src="../themes/images/cancel.png" alt="【关闭】" />' });
                    });
                },
                error: function (msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，获取数据失败！", Icon: IconType.Warning }); },
                beforeSend: function () { $("#LoadingPanel").fadeIn("slow"); },
                complete: function () { $("#LoadingPanel").fadeOut("fast"); }
            })
        }

        $(document).ready(function () {
            //debugger;
            GetDatas();
            $("#btnSearch").click(function () {
                GetDatas();
                return false;
            })
            $("#numPerPageSelect").change(function () {
                $("#pageNum").val(1);
                $("#selectedId").val("");
                GetDatas();
            })
            //        $("div.button").hover(function() { $(this).addClass("buttonHover"); },
            //                                 function() { $(this).removeClass("buttonHover"); });
            
            //绑定更新和删除按钮事件
            addWindow = $("#btnAdd").wBox({ title: "新增线索信息", requestType: "iframe", target: "EditSalesLeads.aspx?Type=add", iframeWH: { width: 600, height: 350} });

            $("#btnUpdate").click(function () {
                if ($(this).attr("disabled") != "disabled") {
                    var brandId = $("#selectedLeadsID").val();
                    if (parseInt(brandId) > 0) {
                        addWindow = $("#selectedLeadsID").wBox({ title: "修改线索信息", requestType: "iframe", target: "EditSalesLeads.aspx?Type=update&LeadId=" + brandId, iframeWH: { width: 600, height: 350} });
                        addWindow.showBox();
                    }
                    else {
                        $.Messager.Alert({ Title: '系统消息', Message: "请选择要修改的线索！", Icon: IconType.Warning });
                    }
                    return false;
                }
            })

            $("#btnDelete").click(function () {
                if ($(this).attr("disabled") != "disabled") {
                    var id = $("#selectedLeadsID").val();
                    //alert(id);
                    if (parseInt(id) > 0) {
                        $.Messager.Confirm({ Title: '系统警告', Message: '你确定要删除该线索信息吗?', Icon: IconType.Question,
                            Oncallback: function (IsYes, siteMapId) {
                                if (IsYes) { DeleteData(id); }
                            }
                        })
                    }
                    else {
                        $.Messager.Alert({ Title: '系统消息', Message: "请选择要删除的线索！", Icon: IconType.Warning });
                    }
                    return false;
                }
            })
        })
    </script>
</head>
<body style="background-color: #FFF; overflow:visible">
    <form id="form1" runat="server">
    <div>
       <table width="100%">
            <tr>
                <td>
                    <div class="searchBar" style="padding: 4px 5px;">
                        <ul>
                            <li style="float: left;"><span>单号：</span>
                                <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
                            </li>
                            <li style="float: left;"><span>公司名称：</span>
                                <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                            </li>
                            <li style="float: left; padding-left: 5px;"><span>制单日期：</span>
                                <asp:TextBox ID="txtDate" runat="server" Width="100" onClick="WdatePicker({skin:'ext'})"></asp:TextBox>
                            </li>
                            <li style="float: left; padding-left: 20px">
                                <div class="buttonActive">
                                    <div class="buttonContent">
                                        <asp:Button ID="btnSearch" runat="server" Text="查询" ToolTip="查询仓库信息" CssClass="serverButton"/>
                                    </div>
                                </div>
                            </li>
                            <li style="clear: both" ></li>
                        </ul>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                <div class="pageContent">
                    <div class="panelBar">
                        <ul class="toolBar">
                            <li class=""><asp:LinkButton ID="btnAdd" runat="server" CssClass="add"><span>添加线索信息</span> </asp:LinkButton></li>
                            <li class="line">line</li>
                            <li class=""><asp:LinkButton ID="btnUpdate" runat="server" CssClass="edit"><span>修改线索信息</span> </asp:LinkButton></li>
                            <li class="line">line</li>
                            <li class=""><asp:LinkButton ID="btnDelete" runat="server" CssClass="delete"><span>删除线索信息</span> </asp:LinkButton></li>
                            <li class="line">line</li>
                            <li class="">
                                <%--<asp:Button ID="btnhidDelete" runat="server" Text="" Style="display: none;" OnClick="btnhidDelete_Click" />--%>
                                <input type="hidden" style="display: none;" id="selectedLeadsID" runat="server" />
                            </li>
                        </ul>
                    </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="pageContent">
                        <div class="tableList">
                            <table class="list" width="100%" id="ActiveList">
                                <thead>
                                    <tr>                                        
                                        <th  style="cursor: pointer;" colname="FNumber">
                                            <span style="float: left">单号</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>
                                        <th width="250" style="cursor: pointer;" colname="FComName">
                                            <span style="float: left">公司名称</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>
                                        <th style="cursor: pointer;" colname="FAddress">
                                            <span style="float: left">公司地址</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>   
                                        <th style="cursor: pointer;" colname="FProducts" >
                                            <span style="float: left">经营产品</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>    
                                        <th style="cursor: pointer;" colname="FWebsite" >
                                            <span style="float: left">客户网站</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>    
                                        <th style="cursor: pointer;" colname="EmpName" >
                                            <span style="float: left">业务员</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th> 
                                        <th style="cursor: pointer;" colname="FArea" >
                                            <span style="float: left">销售区域</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>    
                                        <th style="cursor: pointer;" colname="FChannel" >
                                            <span style="float: left">销售渠道</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>    
                                        <th style="cursor: pointer;" colname="FDate" >
                                            <span style="float: left">制单日期</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>
                                        <th style="cursor: pointer;" colname="FMakerName" >
                                            <span style="float: left">制单人</span> <span style="float: right;" class="sortIcon">
                                            </span>
                                        </th>
                                        <th  valign="middle" style="cursor: pointer;" >
                                             <span>设置</span>
                                        </th>                                   
                                    </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>   
                         <div class="panelBar">
                                            <div class="pages">
                                                <span>每页显示</span>
                                                <div style="float: left">
                                                    <select id="numPerPageSelect" runat="server">                                                       
                                                        <option>10</option>
                                                        <option selected="selected">20</option>                                                       
                                                        <option>30</option>                                                        
                                                        <option>50</option>
                                                    </select>
                                                </div>
                                                <span id="pageMsg"></span>
                                            </div>
                                            <div id="pageId" class="pagination" targettype="navTab" pagenumshown="10">
                                            </div>
                                        </div>                    
                    </div>
                </td>
            </tr>  
            <tr>
                                <td>
                                    <input type="hidden" id="pageNum" name="pageNum" value="1" runat="server" />
                                    <input type="hidden" id="orderField" name="orderField" value="FDate" runat="server" />
                                    <input type="hidden" id="orderValue" name="orderValue" value="desc" runat="server" />
                                </td>
                            </tr>         
        </table>
    </div>
    <div class="panelFooter">
                    <div class="panelFooterContent">
                    </div>
                </div>
    <div id="LoadingPanel" style="display: none;">
        <div id='background' class='background'>
        </div>
        <div id='progressBar' class='progressBar'>
            数据加载中，请稍等...</div>
    </div>
    </form>
</body>
</html>
